package com.hmy.staff.controller;

import com.hmy.staff.domain.HmyStaff;
import com.hmy.staff.service.HmyStaffService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: wxl
 * @Date: 2024/1/29 15:12
 * @Description:
 */

@RestController
@RequestMapping("/staff")
public class StaffController extends BaseController {

    @Autowired
    private HmyStaffService staffService;

    /**
     * 获取用户列表
     */
//    @RequiresPermissions("hmy:staff:list")
    @GetMapping("/list")
    public TableDataInfo list(HmyStaff staff)
    {
        startPage();
        List<HmyStaff> list = staffService.selectStaffList(staff);
        return getDataTable(list);
    }

    @GetMapping("/nameList")
    public AjaxResult nameList(HmyStaff staff)
    {
        return AjaxResult.success("查询成功",staffService.selectStaffList(staff));
    }

    /**
     * 返回员工编码，进行匹配
     *
     * @param staffCode 员工ID
     * @return 员工对象信息
     */
    @GetMapping("/StaffCode/{staffCode}")
    public AjaxResult selectByCode(@PathVariable String staffCode){
        return AjaxResult.success("查询成功",staffService.selectByStaffCode(staffCode));
    }

    /**
     * 根据员工编号获取详细信息
     */
//    @RequiresPermissions("hmy:staff:query")
    @GetMapping(value = "/{staffId}")
    public AjaxResult getInfo(@PathVariable Long staffId)
    {
        return success(staffService.selectStaffById(staffId));
    }

    /**
     * 新增员工信息
     */
//    @RequiresPermissions("system:staff:add")
//    @Log(title = "员工管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody HmyStaff staff)
    {
        return toAjax(staffService.insertStaff(staff));
    }

    /**
     * 修改员工信息
     */
//    @RequiresPermissions("system:staff:edit")
    @Log(title = "员工管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody HmyStaff staff)
    {
        return toAjax(staffService.updateStaff(staff));
    }

    /**
     * 删除员工信息
     */
//    @RequiresPermissions("system:staff:remove")
//    @Log(title = "员工管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{staffIds}")
    public AjaxResult remove(@PathVariable Long[] staffIds)
    {
        return toAjax(staffService.deleteStaffByIds(staffIds));
    }

}
